/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.juani.test.model.impl;

import com.juani.test.model.Client;
import com.juani.test.model.ClientModel;
import com.juani.test.model.ClientSoap;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.json.JSON;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.util.PortalUtil;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import java.io.Serializable;

import java.sql.Types;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * The base model implementation for the Client service. Represents a row in the &quot;test_Client&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link com.juani.test.model.ClientModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link ClientImpl}.
 * </p>
 *
 * @author Juan Martin Ruiz
 * @see ClientImpl
 * @see com.juani.test.model.Client
 * @see com.juani.test.model.ClientModel
 * @generated
 */
@JSON(strict = true)
public class ClientModelImpl extends BaseModelImpl<Client>
	implements ClientModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a client model instance should use the {@link com.juani.test.model.Client} interface instead.
	 */
	public static final String TABLE_NAME = "test_Client";
	public static final Object[][] TABLE_COLUMNS = {
			{ "clientId", Types.BIGINT },
			{ "companyId", Types.BIGINT },
			{ "userId", Types.BIGINT },
			{ "userName", Types.VARCHAR },
			{ "createDate", Types.TIMESTAMP },
			{ "modifiedDate", Types.TIMESTAMP },
			{ "firstName", Types.VARCHAR },
			{ "lastName", Types.VARCHAR },
			{ "address", Types.VARCHAR },
			{ "email", Types.VARCHAR },
			{ "phone", Types.VARCHAR },
			{ "movil", Types.VARCHAR }
		};
	public static final String TABLE_SQL_CREATE = "create table test_Client (clientId LONG not null primary key,companyId LONG,userId LONG,userName VARCHAR(75) null,createDate DATE null,modifiedDate DATE null,firstName VARCHAR(75) null,lastName VARCHAR(75) null,address VARCHAR(75) null,email VARCHAR(75) null,phone VARCHAR(75) null,movil VARCHAR(75) null)";
	public static final String TABLE_SQL_DROP = "drop table test_Client";
	public static final String ORDER_BY_JPQL = " ORDER BY client.lastName ASC";
	public static final String ORDER_BY_SQL = " ORDER BY test_Client.lastName ASC";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.com.juani.test.model.Client"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.com.juani.test.model.Client"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.column.bitmask.enabled.com.juani.test.model.Client"),
			true);
	public static long EMAIL_COLUMN_BITMASK = 1L;
	public static long FIRSTNAME_COLUMN_BITMASK = 2L;
	public static long LASTNAME_COLUMN_BITMASK = 4L;
	public static long MOVIL_COLUMN_BITMASK = 8L;
	public static long PHONE_COLUMN_BITMASK = 16L;

	/**
	 * Converts the soap model instance into a normal model instance.
	 *
	 * @param soapModel the soap model instance to convert
	 * @return the normal model instance
	 */
	public static Client toModel(ClientSoap soapModel) {
		if (soapModel == null) {
			return null;
		}

		Client model = new ClientImpl();

		model.setClientId(soapModel.getClientId());
		model.setCompanyId(soapModel.getCompanyId());
		model.setUserId(soapModel.getUserId());
		model.setUserName(soapModel.getUserName());
		model.setCreateDate(soapModel.getCreateDate());
		model.setModifiedDate(soapModel.getModifiedDate());
		model.setFirstName(soapModel.getFirstName());
		model.setLastName(soapModel.getLastName());
		model.setAddress(soapModel.getAddress());
		model.setEmail(soapModel.getEmail());
		model.setPhone(soapModel.getPhone());
		model.setMovil(soapModel.getMovil());

		return model;
	}

	/**
	 * Converts the soap model instances into normal model instances.
	 *
	 * @param soapModels the soap model instances to convert
	 * @return the normal model instances
	 */
	public static List<Client> toModels(ClientSoap[] soapModels) {
		if (soapModels == null) {
			return null;
		}

		List<Client> models = new ArrayList<Client>(soapModels.length);

		for (ClientSoap soapModel : soapModels) {
			models.add(toModel(soapModel));
		}

		return models;
	}

	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.com.juani.test.model.Client"));

	public ClientModelImpl() {
	}

	public long getPrimaryKey() {
		return _clientId;
	}

	public void setPrimaryKey(long primaryKey) {
		setClientId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_clientId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	public Class<?> getModelClass() {
		return Client.class;
	}

	public String getModelClassName() {
		return Client.class.getName();
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("clientId", getClientId());
		attributes.put("companyId", getCompanyId());
		attributes.put("userId", getUserId());
		attributes.put("userName", getUserName());
		attributes.put("createDate", getCreateDate());
		attributes.put("modifiedDate", getModifiedDate());
		attributes.put("firstName", getFirstName());
		attributes.put("lastName", getLastName());
		attributes.put("address", getAddress());
		attributes.put("email", getEmail());
		attributes.put("phone", getPhone());
		attributes.put("movil", getMovil());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long clientId = (Long)attributes.get("clientId");

		if (clientId != null) {
			setClientId(clientId);
		}

		Long companyId = (Long)attributes.get("companyId");

		if (companyId != null) {
			setCompanyId(companyId);
		}

		Long userId = (Long)attributes.get("userId");

		if (userId != null) {
			setUserId(userId);
		}

		String userName = (String)attributes.get("userName");

		if (userName != null) {
			setUserName(userName);
		}

		Date createDate = (Date)attributes.get("createDate");

		if (createDate != null) {
			setCreateDate(createDate);
		}

		Date modifiedDate = (Date)attributes.get("modifiedDate");

		if (modifiedDate != null) {
			setModifiedDate(modifiedDate);
		}

		String firstName = (String)attributes.get("firstName");

		if (firstName != null) {
			setFirstName(firstName);
		}

		String lastName = (String)attributes.get("lastName");

		if (lastName != null) {
			setLastName(lastName);
		}

		String address = (String)attributes.get("address");

		if (address != null) {
			setAddress(address);
		}

		String email = (String)attributes.get("email");

		if (email != null) {
			setEmail(email);
		}

		String phone = (String)attributes.get("phone");

		if (phone != null) {
			setPhone(phone);
		}

		String movil = (String)attributes.get("movil");

		if (movil != null) {
			setMovil(movil);
		}
	}

	@JSON
	public long getClientId() {
		return _clientId;
	}

	public void setClientId(long clientId) {
		_clientId = clientId;
	}

	@JSON
	public long getCompanyId() {
		return _companyId;
	}

	public void setCompanyId(long companyId) {
		_companyId = companyId;
	}

	@JSON
	public long getUserId() {
		return _userId;
	}

	public void setUserId(long userId) {
		_userId = userId;
	}

	public String getUserUuid() throws SystemException {
		return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
	}

	public void setUserUuid(String userUuid) {
		_userUuid = userUuid;
	}

	@JSON
	public String getUserName() {
		if (_userName == null) {
			return StringPool.BLANK;
		}
		else {
			return _userName;
		}
	}

	public void setUserName(String userName) {
		_userName = userName;
	}

	@JSON
	public Date getCreateDate() {
		return _createDate;
	}

	public void setCreateDate(Date createDate) {
		_createDate = createDate;
	}

	@JSON
	public Date getModifiedDate() {
		return _modifiedDate;
	}

	public void setModifiedDate(Date modifiedDate) {
		_modifiedDate = modifiedDate;
	}

	@JSON
	public String getFirstName() {
		if (_firstName == null) {
			return StringPool.BLANK;
		}
		else {
			return _firstName;
		}
	}

	public void setFirstName(String firstName) {
		_columnBitmask |= FIRSTNAME_COLUMN_BITMASK;

		if (_originalFirstName == null) {
			_originalFirstName = _firstName;
		}

		_firstName = firstName;
	}

	public String getOriginalFirstName() {
		return GetterUtil.getString(_originalFirstName);
	}

	@JSON
	public String getLastName() {
		if (_lastName == null) {
			return StringPool.BLANK;
		}
		else {
			return _lastName;
		}
	}

	public void setLastName(String lastName) {
		_columnBitmask = -1L;

		if (_originalLastName == null) {
			_originalLastName = _lastName;
		}

		_lastName = lastName;
	}

	public String getOriginalLastName() {
		return GetterUtil.getString(_originalLastName);
	}

	@JSON
	public String getAddress() {
		if (_address == null) {
			return StringPool.BLANK;
		}
		else {
			return _address;
		}
	}

	public void setAddress(String address) {
		_address = address;
	}

	@JSON
	public String getEmail() {
		if (_email == null) {
			return StringPool.BLANK;
		}
		else {
			return _email;
		}
	}

	public void setEmail(String email) {
		_columnBitmask |= EMAIL_COLUMN_BITMASK;

		if (_originalEmail == null) {
			_originalEmail = _email;
		}

		_email = email;
	}

	public String getOriginalEmail() {
		return GetterUtil.getString(_originalEmail);
	}

	@JSON
	public String getPhone() {
		if (_phone == null) {
			return StringPool.BLANK;
		}
		else {
			return _phone;
		}
	}

	public void setPhone(String phone) {
		_columnBitmask |= PHONE_COLUMN_BITMASK;

		if (_originalPhone == null) {
			_originalPhone = _phone;
		}

		_phone = phone;
	}

	public String getOriginalPhone() {
		return GetterUtil.getString(_originalPhone);
	}

	@JSON
	public String getMovil() {
		if (_movil == null) {
			return StringPool.BLANK;
		}
		else {
			return _movil;
		}
	}

	public void setMovil(String movil) {
		_columnBitmask |= MOVIL_COLUMN_BITMASK;

		if (_originalMovil == null) {
			_originalMovil = _movil;
		}

		_movil = movil;
	}

	public String getOriginalMovil() {
		return GetterUtil.getString(_originalMovil);
	}

	public long getColumnBitmask() {
		return _columnBitmask;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		return ExpandoBridgeFactoryUtil.getExpandoBridge(getCompanyId(),
			Client.class.getName(), getPrimaryKey());
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		ExpandoBridge expandoBridge = getExpandoBridge();

		expandoBridge.setAttributes(serviceContext);
	}

	@Override
	public Client toEscapedModel() {
		if (_escapedModelProxy == null) {
			_escapedModelProxy = (Client)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelProxyInterfaces,
					new AutoEscapeBeanHandler(this));
		}

		return _escapedModelProxy;
	}

	@Override
	public Object clone() {
		ClientImpl clientImpl = new ClientImpl();

		clientImpl.setClientId(getClientId());
		clientImpl.setCompanyId(getCompanyId());
		clientImpl.setUserId(getUserId());
		clientImpl.setUserName(getUserName());
		clientImpl.setCreateDate(getCreateDate());
		clientImpl.setModifiedDate(getModifiedDate());
		clientImpl.setFirstName(getFirstName());
		clientImpl.setLastName(getLastName());
		clientImpl.setAddress(getAddress());
		clientImpl.setEmail(getEmail());
		clientImpl.setPhone(getPhone());
		clientImpl.setMovil(getMovil());

		clientImpl.resetOriginalValues();

		return clientImpl;
	}

	public int compareTo(Client client) {
		int value = 0;

		value = getLastName().compareTo(client.getLastName());

		if (value != 0) {
			return value;
		}

		return 0;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		Client client = null;

		try {
			client = (Client)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = client.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
		ClientModelImpl clientModelImpl = this;

		clientModelImpl._originalFirstName = clientModelImpl._firstName;

		clientModelImpl._originalLastName = clientModelImpl._lastName;

		clientModelImpl._originalEmail = clientModelImpl._email;

		clientModelImpl._originalPhone = clientModelImpl._phone;

		clientModelImpl._originalMovil = clientModelImpl._movil;

		clientModelImpl._columnBitmask = 0;
	}

	@Override
	public CacheModel<Client> toCacheModel() {
		ClientCacheModel clientCacheModel = new ClientCacheModel();

		clientCacheModel.clientId = getClientId();

		clientCacheModel.companyId = getCompanyId();

		clientCacheModel.userId = getUserId();

		clientCacheModel.userName = getUserName();

		String userName = clientCacheModel.userName;

		if ((userName != null) && (userName.length() == 0)) {
			clientCacheModel.userName = null;
		}

		Date createDate = getCreateDate();

		if (createDate != null) {
			clientCacheModel.createDate = createDate.getTime();
		}
		else {
			clientCacheModel.createDate = Long.MIN_VALUE;
		}

		Date modifiedDate = getModifiedDate();

		if (modifiedDate != null) {
			clientCacheModel.modifiedDate = modifiedDate.getTime();
		}
		else {
			clientCacheModel.modifiedDate = Long.MIN_VALUE;
		}

		clientCacheModel.firstName = getFirstName();

		String firstName = clientCacheModel.firstName;

		if ((firstName != null) && (firstName.length() == 0)) {
			clientCacheModel.firstName = null;
		}

		clientCacheModel.lastName = getLastName();

		String lastName = clientCacheModel.lastName;

		if ((lastName != null) && (lastName.length() == 0)) {
			clientCacheModel.lastName = null;
		}

		clientCacheModel.address = getAddress();

		String address = clientCacheModel.address;

		if ((address != null) && (address.length() == 0)) {
			clientCacheModel.address = null;
		}

		clientCacheModel.email = getEmail();

		String email = clientCacheModel.email;

		if ((email != null) && (email.length() == 0)) {
			clientCacheModel.email = null;
		}

		clientCacheModel.phone = getPhone();

		String phone = clientCacheModel.phone;

		if ((phone != null) && (phone.length() == 0)) {
			clientCacheModel.phone = null;
		}

		clientCacheModel.movil = getMovil();

		String movil = clientCacheModel.movil;

		if ((movil != null) && (movil.length() == 0)) {
			clientCacheModel.movil = null;
		}

		return clientCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(25);

		sb.append("{clientId=");
		sb.append(getClientId());
		sb.append(", companyId=");
		sb.append(getCompanyId());
		sb.append(", userId=");
		sb.append(getUserId());
		sb.append(", userName=");
		sb.append(getUserName());
		sb.append(", createDate=");
		sb.append(getCreateDate());
		sb.append(", modifiedDate=");
		sb.append(getModifiedDate());
		sb.append(", firstName=");
		sb.append(getFirstName());
		sb.append(", lastName=");
		sb.append(getLastName());
		sb.append(", address=");
		sb.append(getAddress());
		sb.append(", email=");
		sb.append(getEmail());
		sb.append(", phone=");
		sb.append(getPhone());
		sb.append(", movil=");
		sb.append(getMovil());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(40);

		sb.append("<model><model-name>");
		sb.append("com.juani.test.model.Client");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>clientId</column-name><column-value><![CDATA[");
		sb.append(getClientId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>companyId</column-name><column-value><![CDATA[");
		sb.append(getCompanyId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>userId</column-name><column-value><![CDATA[");
		sb.append(getUserId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>userName</column-name><column-value><![CDATA[");
		sb.append(getUserName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>createDate</column-name><column-value><![CDATA[");
		sb.append(getCreateDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>modifiedDate</column-name><column-value><![CDATA[");
		sb.append(getModifiedDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>firstName</column-name><column-value><![CDATA[");
		sb.append(getFirstName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>lastName</column-name><column-value><![CDATA[");
		sb.append(getLastName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>address</column-name><column-value><![CDATA[");
		sb.append(getAddress());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>email</column-name><column-value><![CDATA[");
		sb.append(getEmail());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>phone</column-name><column-value><![CDATA[");
		sb.append(getPhone());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>movil</column-name><column-value><![CDATA[");
		sb.append(getMovil());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = Client.class.getClassLoader();
	private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
			Client.class
		};
	private long _clientId;
	private long _companyId;
	private long _userId;
	private String _userUuid;
	private String _userName;
	private Date _createDate;
	private Date _modifiedDate;
	private String _firstName;
	private String _originalFirstName;
	private String _lastName;
	private String _originalLastName;
	private String _address;
	private String _email;
	private String _originalEmail;
	private String _phone;
	private String _originalPhone;
	private String _movil;
	private String _originalMovil;
	private long _columnBitmask;
	private Client _escapedModelProxy;
}